package com.baizhi.controller;

import com.baizhi.common.PageDTO;
import com.baizhi.entity.Patient;
import com.baizhi.service.PatientService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("patient")
public class PatientController {
    private PatientService patientService;
    @Autowired
    public void setPatientService(PatientService patientService) {
        this.patientService = patientService;
    }

    @RequestMapping("showPatient")
    public String showPatient(PageDTO pDTO, Map map){
        PageInfo<Patient> pageInfo = patientService.selectByPage(pDTO.getName(), pDTO.getPageNum(), pDTO.getPageSize());
        map.put("list",pageInfo.getList());
        map.put("totalPage",pageInfo.getPages());
        map.put("name",pDTO.getName());
        map.put("pageNum",pDTO.getPageNum());
        return "manager/patient/patientList";
    }
    @RequestMapping("addPatient")
    public String addPatient(Patient patient){
        patientService.insertPatient(patient);
        return "redirect:showPatient";
    }
    @RequestMapping("removePatient")
    public String removePatient(Integer pid){
        patientService.deletePatient(pid);
        return "redirect:showPatient";
    }
    @RequestMapping("getOne")
    public String getOnePatient(Integer pid,Map map){
        Patient patient = patientService.selectById(pid);
        map.put("patient",patient);
        return "manager/patient/updatePatient";
    }
    @RequestMapping("updatePatient")
    public String updatePatient(Patient patient){
        System.out.println("修改方法："+patient);
        patientService.updatePatient(patient);
        return "redirect:showPatient";
    }
    @RequestMapping("guaHao")
    public String guaHao(Integer pid,Map map){
        Patient patient = patientService.selectById(pid);
        map.put("p",patient);
        return "manager/patient/patientRegist";
    }
}
